

import java.io.IOException;
import java.util.List;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entities.AskForAdding;

import sessionbeans.AdminBeanRemote;

/**
 * Servlet implementation class AbilityRetrievalServlet
 */
public class AbilityRetrievalServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AbilityRetrievalServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		List<AskForAdding> abilityRequests;
		
		try {
			InitialContext context = new InitialContext();
			Object ref = context.lookup("AdminBeanRemote");
			AdminBeanRemote adminBean = (AdminBeanRemote)PortableRemoteObject.narrow(ref, AdminBeanRemote.class);
			
			abilityRequests = adminBean.getAbilityRequests();
			request.getSession().setAttribute("abilities",abilityRequests);
			response.sendRedirect("AbilityAddingPage.jsp");
		} catch (NamingException e) {
			response.getWriter().println("Naming Exception");
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
